﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KongZhiTaiTest
{
    public class MaoPaoPaixu
    {

        public string AAA { get; set; }
        public string BBN { get; set; }
        public override string ToString()
        {
            return "AAA: "+this.AAA+" "+"BBN: "+ this.BBN+";";
        }
        //public Array Filter(Array arr)
        //{
        //    int[] intarr = new int[10];
        //    for (int i = 0; i <= 10; i++ )
        //    {
        //        intarr[i] = i+1;
        //    }
        //    return intarr;
        //}

        public int[] PopSort(int[] arr)
        {
            for (int i = 0; i < arr.Length - 1; i++)
            {
                for (int j = i + 1; j < arr.Length; j++)
                {
                    if (arr[i] > arr[j])
                    {
                        JiaoHuanWz(arr[i], arr[j]);
                    }
                }
            }
            return arr;
        }
        /// <summary>
        /// 联系冒泡排序
        /// </summary>
        /// <param name="arr"></param>
        /// <returns></returns>
        public int[] Pop(int[] arr)
        {
            for (int i = 0; i < arr.Length - 1; i++)
            {
                for (int j = i + 1; j < arr.Length; j++) 
                {
                    if (arr[i] > arr[j])
                    {
                        int temp = arr[i];
                        arr[i] = arr[j];
                        arr[j] = temp;
                    }
                }
            }
            return arr;
        }

        public int[] OrderSer(int lenght)
        {
            int[] result = new int[lenght];
            for (int i = 0; i < lenght; i++)
            {
                result[i] = i;
            }
            return result;
        }

        public IList<int> NewInstance(IList<int> data, int lenght)
        {
            IList<int> instance;
            if (data is Array)
            {
                instance = new int[lenght];
            }
            else
            {
                instance = new List<int>(lenght);
                for (int i = 0; i < lenght; i++)
                {
                    instance.Add(0);
                }
            }
            return instance;
        }

        /// <summary>
        /// 交换位置
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>

        public void JiaoHuanWz(int x, int y)
        {
            int temp = x;
            x = y;
            y = temp;
        }


        public int[] Filter(int[] arr,int min)
        {
            List<int> arrList = new List<int>();
            for (int i = 0; i < arr.Length; i++)
            {
                if (arr[i] > min)
                {
                    arrList.Add(arr[i]);
                }
            }
            return arrList.ToArray();
        }
        public int Reduce(int[] arr)
        {
            int sum = 0;
            for (int i = 0; i < arr.Length; i++)
            {
                sum += arr[i];
            }
            return sum;
        }


        public void PopDesc(int[] arry)
        {
            int temp;
            for(int i = arry.Length-1; i>0; i--)
            {
                //从左向右遍历
                for(int j = 0; j < i; j++)
                {
                    //倒叙的话右边是最小值，
                    if (arry[j] < arry[j + 1])
                    {
                        temp = arry[j];
                        arry[j] = arry[j + 1];
                        arry[j + 1] = temp;
                    }
                }
            }
        }

        /// <summary>
        /// 获取最大值
        /// </summary>
        /// <param name="arr"></param>
        /// <returns></returns>
        public int GetMaxValue(int[] arr)
        {
            int temp;
            for(int i = 0; i < arr.Length - 1; i++)
            {
                //按升序排列
                if (arr[i] > arr[i + 1])
                {
                    temp = arr[i];
                    arr[i] = arr[i + 1];
                    arr[i + 1] = temp;
                }
            }
            return arr[arr.Length - 1];
        }

        /// <summary>
        /// 获取最小值
        /// </summary>
        /// <param name="arr"></param>
        /// <returns></returns>
        public int GetMinValue(int[] arr)
        {
            int temp;
            for (int i = 0; i < arr.Length - 1; i++)
            {
                //按降序排列
                if (arr[i] < arr[i + 1])
                {
                    temp = arr[i];
                    arr[i] = arr[i + 1];
                    arr[i + 1] = temp;
                }
            }
            return arr[arr.Length - 1];
        }

    }

}
